package com.aidong.service;

/**
 * Created by john on 16-11-2.
 */
import com.aidong.common.JobConsts;
import com.aidong.dao.wills.ShopDprDao;
import com.aidong.util.DateUtil;
import com.aidong.util.ExportUtil;
import com.aidong.util.FileCheckUtil;
import com.aidong.util.ReportUtil;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

@Service
public class MonthDprService extends BaseJobService {
    protected Logger log = Logger.getLogger(MonthDprService.class);
    @Resource
    ShopDprDao shopDprDao;
    @Resource
    ReportUtil reportUtil;

    public MonthDprService() {
    }

    public synchronized void doJob() {
        Thread th1 = new Thread() {
            public void run() {
                try {
                    try {
                        MonthDprService.this.doMonthDpr();
                    } catch (Exception var5) {
                        var5.printStackTrace();
                    }

                } finally {
                    ;
                }
            }
        };
        th1.start();
    }

    private void doMonthDpr() throws Exception {
        try {
            Timestamp e = DateUtil.getCurrentTimestamp();
            String cur = DateUtil.formatDate(e, DateUtil.DATE_PATTERN_YYYYMMDD);
            String curDate = DateUtil.addDays(cur, -1);
            HashMap commonData = new HashMap();
            commonData.put("dateFrom", curDate);
            commonData.put("dateTo", curDate);
            Date tmpDate = DateUtil.addMonths(DateUtil.formatDate(curDate), -1);
            HashMap data1 = new HashMap();
            HashMap data2 = new HashMap();
            ArrayList listAll = new ArrayList();
            List list = this.shopDprDao.getDprDataOfList(DateUtil.formatDate(DateUtil.getFirstDay(tmpDate)), DateUtil.formatDate(DateUtil.getLastDay(tmpDate)));
            listAll.addAll(list);
            List list2 = this.shopDprDao.getDprDataOfTotal(DateUtil.formatDate(DateUtil.getFirstDay(tmpDate)), DateUtil.formatDate(DateUtil.getLastDay(tmpDate)));
            listAll.addAll(list2);
            data1.putAll(commonData);
            data1.put("list", listAll);
            data2.putAll(commonData);
            data2.put("list", list);
            String fileName = curDate + "_" + JobConsts.TEMPLATE_NAME_DPR_INCOME + JobConsts.EXCEL_SUFFIX;
            String fileChName = curDate + "_" + JobConsts.CH_NAME_DPR_INCOME_MONTH + JobConsts.EXCEL_SUFFIX;
            String filePath = this.getDownloadPath() + curDate + "\\" + JobConsts.TEMPLATE_NAME_DPR_INCOME;
            String fileDbPath = curDate + "\\" + JobConsts.TEMPLATE_NAME_DPR_INCOME;
            FileCheckUtil.checkFilePath(filePath);
            ExportUtil.exportExcel(filePath, fileName, this.getTemplatePath(), JobConsts.TEMPLATE_NAME_DPR_INCOME + JobConsts.EXCEL_SUFFIX, data1);
            this.reportUtil.addReportFile("07", fileName, fileChName, fileDbPath, curDate, "ALL");
        } catch (Exception var15) {
            var15.printStackTrace();
            this.log.error("生成(DPR收入月)失败");
            return;
        }

        this.log.info("生成(DPR收入月)成功");
    }

    public void createMonthDpr(String createts) throws Exception {
        try {
            HashMap commonData = new HashMap();
            commonData.put("date", createts);
            Date tmpDate = DateUtil.formatDate(createts);
            HashMap data1 = new HashMap();
            HashMap data2 = new HashMap();
            ArrayList listAll = new ArrayList();
            List list = this.shopDprDao.getDprDataOfList(DateUtil.formatDate(DateUtil.getFirstDay(tmpDate)), DateUtil.formatDate(DateUtil.getLastDay(tmpDate)));
            listAll.addAll(list);
            List list2 = this.shopDprDao.getDprDataOfTotal(DateUtil.formatDate(DateUtil.getFirstDay(tmpDate)), DateUtil.formatDate(DateUtil.getLastDay(tmpDate)));
            listAll.addAll(list2);
            data1.putAll(commonData);
            data1.put("list", listAll);
            data2.putAll(commonData);
            data2.put("list", list);
            String fileName = createts + "_" + JobConsts.TEMPLATE_NAME_DPR_INCOME + JobConsts.EXCEL_SUFFIX;
            String fileChName = createts + "_" + JobConsts.CH_NAME_DPR_INCOME_MONTH + JobConsts.EXCEL_SUFFIX;
            String filePath = this.getDownloadPath() + createts + "\\" + JobConsts.TEMPLATE_NAME_DPR_INCOME;
            String fileDbPath = createts + "\\" + JobConsts.TEMPLATE_NAME_DPR_INCOME;
            FileCheckUtil.checkFilePath(filePath);
            ExportUtil.exportExcel(filePath, fileName, this.getTemplatePath(), JobConsts.TEMPLATE_NAME_DPR_INCOME + JobConsts.EXCEL_SUFFIX, data1);
            this.reportUtil.addReportFile("07", fileName, fileChName, fileDbPath, createts, "ALL");
        } catch (Exception var14) {
            var14.printStackTrace();
            this.log.error("生成(DPR收入月)失败");
            return;
        }

        this.log.info("生成(DPR收入月)成功");
    }
}
